package com.alibaba.nacos.core.distributed.distro.task.execute;

import com.alibaba.nacos.consistency.DataOperation;
import com.alibaba.nacos.core.distributed.distro.component.DistroCallback;
import com.alibaba.nacos.core.distributed.distro.component.DistroDataStorage;
import com.alibaba.nacos.core.distributed.distro.component.DistroTransportAgent;
import com.alibaba.nacos.core.distributed.distro.entity.DistroData;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Getter
@Component
@Scope("prototype")
public class DistroSyncChangeTask
        extends AbstractDistroExecuteTask {

    private DataOperation dataOperation = DataOperation.CHANGE;

    @Autowired
    private DistroDataStorage distroDataStorage;
    @Autowired
    private DistroTransportAgent distroTransportAgent;

    @Override
    protected boolean doExecute() {
        return false;
    }

    @Override
    protected void doExecuteWithCallback(DistroCallback callback) {
        DistroData distroData = distroDataStorage.generateDistroData(getDistroKey());
        if (distroData != null) {
            distroData.setType(dataOperation);
        }

        distroTransportAgent.syncData(distroData, getDistroKey().getTargetServer(), callback);
    }
}
